<?php
include_once("config.php");
if (isset($_SESSION['adminName'])){
	$isAdmin=true;
}else{
	$isAdmin=false;
}
if (isset($_POST['restuarantname']) && isset($_POST['restuarantaddress']) && isset($_POST['restuarantaverageconsumption']) && isset($_POST['restuarantcuisines']) && isset($_POST['restuarantcontactnumber']) && isset($_POST['restuarantdescription'])){
	$isInputValid=true;
}else{
	$isInputValid=false;
}
if ($isInputValid){
	$restuarantname=mysql_real_escape_string(stripcslashes($_POST['restuarantname']));
	$restuarantaddress=mysql_real_escape_string(stripcslashes($_POST['restuarantaddress']));
	$restuarantaverageconsumption=intval(mysql_real_escape_string(stripcslashes($_POST['restuarantaverageconsumption'])));
	$restuarantcuisines=mysql_real_escape_string(stripcslashes($_POST['restuarantcuisines']));
	$restuarantcontactnumber=mysql_real_escape_string(stripcslashes($_POST['restuarantcontactnumber']));
	$restuarantdescription=mysql_real_escape_string(stripcslashes($_POST['restuarantdescription']));
  
  if (!empty($restuarantaddress) && !empty($restuarantaverageconsumption)){
	  $queryStr="INSERT INTO restaurant VALUES('$restuarantname','$restuarantaddress','$restuarantaverageconsumption','$restuarantcuisines','$restuarantcontactnumber','$restuarantdescription')";
	  mysql_query($queryStr) or die("Error: ".mysql_error()."<br/>go back <a href='viewrestuarant.php'>here</a>");
	  $isSuccessful=true;
  }else{
  	$isSuccessful=false;
  }
}else{
	$isSuccessful=false;
}
if ($isAdmin && $isSuccessful){
  header("location: viewrestuarant.php");
}else if(!$isAdmin){
  header("location: adminIndex.php");
}else if(!$isInputValid){
	echo "Input is not valid!<br/> go back <a href='viewrestuarant.php'>here</a>";
}else{
	echo "Input format does not fulfill requirements. <br/> go back <a href='viewrestuarant.php'>here</a>";
}
?>
